1

C++ 文の構造

AI037Lesson 8
00:00

C++ において、抽象的な値から実行へと至る道のりは 文から始まります。 式文 は、式の末尾にセミコロンを付けるだけで作成され、コンパイラにその式を評価させ、 flow of control sequentially.

1. The Null Statement

A null statement (;) is a placeholder used when the language requires a statement but your logic does not. While useful in some loops, beware the extraneous null statement—an accidental semicolon after a while or if header can lead to devastating logic errors where the intended body is ignored.

⚠️ Warning (p. 235): An accidental semicolon after a loop header creates a null statement as the body, often resulting in infinite loops.

2. Compound Statements (Blocks)

A compound statement, or block, is a sequence of statements enclosed in curly braces { }. It is treated as a single unit of execution. Blocks define their own scope; names defined inside are invisible outside.

Single Statementval = x + y;std::cout << val;Compound Statement (Block){val = x + y;return val;}
Note (p. 235): Unlike simple statements, a block is not terminated by a semicolon.
main.py
TERMINALbash — 80x24
> Ready. Click "Run" to execute.
>